﻿using System;
using System.Security.Cryptography;

namespace RailwayReservationWeb
{
    public class Checksum
    {
        public static string MD5(byte[] src)
        {
            string strReturn = "";
            var MD5Hash = new MD5CryptoServiceProvider();
            byte[] byteHash = MD5Hash.ComputeHash(src);
            foreach (byte b in byteHash)
                strReturn += b.ToString("x2");
            return strReturn;
        }

        public static string MD5(string str)
        {
            string strReturn = "";
            byte[] byteSource = System.Text.Encoding.UTF8.GetBytes(str);
            var MD5Hash = new MD5CryptoServiceProvider();
            byte[] byteHash = MD5Hash.ComputeHash(byteSource);
            foreach (byte b in byteHash)
                strReturn += b.ToString("x2");
            return strReturn;
        }

        public static string SHA1(string str)
        {
            string strReturn = "";
            byte[] ByteSourceText = System.Text.Encoding.UTF8.GetBytes(str);
            var SHA1Hash = new SHA1CryptoServiceProvider();
            byte[] ByteHash = SHA1Hash.ComputeHash(ByteSourceText);
            foreach (byte b in ByteHash)
                strReturn += b.ToString("x2");
            return strReturn;
        }
    }
}